package net.tycmc.cty.ctyms.timejob.iems.dao;
import java.text.DecimalFormat;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.ResourceBundle;
import java.util.Set;

import com.tycmc.functions.util.NumberFormat;
import net.tycmc.bulb.common.dao.BaseDAO;
import net.tycmc.bulb.common.dao.IBaseDAO;
import net.tycmc.bulb.common.dao.ITransactionDAO;
import net.tycmc.bulb.common.dao.TransactionDAO;
import net.tycmc.bulb.common.datasource.ProxoolDataSource;
import net.tycmc.bulb.common.util.DateUtil;
import net.tycmc.bulb.common.util.MapGetter;
import net.tycmc.bulb.common.util.StringUtil;
import net.tycmc.bulb.dbutil.global.GlobalDBVar;
import net.tycmc.cty.ctyms.timejob.common.DateRegUtil;
import net.tycmc.cty.ctyms.timejob.common.ListUtil;
import net.tycmc.cty.ctyms.timejob.common.MyBaseDAO;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSDAO;
import net.tycmc.cty.ctyms.timejob.common.MyConnectDSTransDAO;
/**
 * @author gaoxiaoxing
 *天远微信公众账户发短信
 */
public class WeChatpublicaccountScoreDAO {
	private IBaseDAO baseDAO;
	private ITransactionDAO tranDAO;
	public ITransactionDAO getTranDAO() {
		return tranDAO;
	}

	public void setTranDAO(ITransactionDAO tranDAO) {
		this.tranDAO = tranDAO;
	}

	public IBaseDAO getBaseDAO() {
		return baseDAO;
	}

	public void setBaseDAO(IBaseDAO baseDAO) {
		this.baseDAO = baseDAO;
	}

	
	public List<Map<String,Object>> getNextTime(){
		String sql="select convert(varchar(10),pnn_nextTime,120)ntime from PostNoteNext";
		return baseDAO.execQuery(sql, new Object[]{});
	}
	public int saveNextOprTime (String nextOprTime){
		String sql="truncate table PostNoteNext;";
		sql+=" insert into PostNoteNext(pnn_nextTime)values('"+nextOprTime+"')";
		return baseDAO.execUpdate(sql, new Object[]{});
	}
	/**
	 * 未绑定微信号发短信
	 **/
	public  boolean getWeChatpublicaccount(List<String> sqlList,List<Object[]> paramsList) {
		StringBuffer sql = new StringBuffer();
		sql.append("SELECT Mobile,SUM(STATE) FROM");
		sql.append(" (select Mobile,STATE=case when aob_id is null then 0 else 1 end,aob_id from CTY_ms.dbo.userinfo left join cty_ms.dbo.AccountWeichatBang on");
		sql.append(" userinfo.userid =AccountWeichatBang.aob_userid and aob_bingtime<getdate() and aob_releasetime>getdate() where mobile is not null and mobile!='' and userbuildtime <getdate() and usefullife >getdate()");
		sql.append(" union all");
		sql.append(" select Mobile,STATE=case when aob_id is null then 0 else 1 end,aob_id from CTY_ms_gcic.dbo.userinfo left join cty_ms_gcic.dbo.AccountWeichatBang on");
		sql.append(" userinfo.userid =AccountWeichatBang.aob_userid and aob_bingtime<getdate() and aob_releasetime>getdate() where mobile is not null and mobile!='' and userbuildtime <getdate() and usefullife >getdate() )result group by Mobile having SUM(STATE)=0");
		List<Map<String, Object>> List=baseDAO.execQuery(sql.toString(), new Object[]{});
		if (List == null || List.size() == 0){
			return false;
		}else{
			int i=0;
			for (i = 0; i < List.size(); i++) {
				Map<String, Object> paramMap = List.get(i);
				String strSQL = "insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)"
						+ "values(?,'625570012188','为了给您提供更好的体验，请绑定“康明斯天远”官方微信服务号,及时接收车辆故障提醒和公司动态。','-1',null);";
				sqlList.add(strSQL);
				paramsList.add(new Object[] {paramMap.get("Mobile")});
				String StrSQL ="insert into weichatsmssendlog (wcssl_OrderNumber,wcssl_SourceNumber,wcssl_MessageContent,wcssl_TransportResult,wcssl_TimingTime)"
						+ "values(?,'625570012188','为了给您提供更好的体验，请绑定“康明斯天远”官方微信服务号,及时接收车辆故障提醒和公司动态。','-1',getdate());";				
				sqlList.add(StrSQL);			
				paramsList.add(new Object[] {paramMap.get("Mobile")});
			}
			sqlList.add("insert into SubTransQueue (OrderNumber,SourceNumber,MessageContent,TransportResult,TimingSendTime)values('13028649188','625570012188','为了给您提供更好的体验，请绑定“康明斯天远”官方微信服务号,及时接收车辆故障提醒和公司动态。','-1',null);");
			paramsList.add(new Object[] {});
				return  tranDAO.batch(sqlList, paramsList);
		}
		
		
	}
}
